/*
 * (c) Copyright Microsoft Corporation. 
 * This source is subject to the Microsoft Public License.
 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL       
 */
package com.microsoft.hsg.applications;

import java.io.InputStream;

import com.microsoft.hsg.Connection;
import com.microsoft.hsg.ConnectionFactory;
import com.microsoft.hsg.HVAccessor;
import com.microsoft.hsg.HVException;
import com.microsoft.hsg.methods.jaxb.JaxbRequest;
import com.microsoft.hsg.methods.jaxb.SimpleRequestTemplate;

/**
 * This RequestTemplate fills in the details to call HealthVault
 * and receive the response.  Online means the user is logged in and
 * we have access to the user token from the session.  Fill in the user
 * token, their record, and make the call.
 */
public class OnlineRequestTemplate extends SimpleRequestTemplate
{
	
	/** The connection. */
	Connection connection;

	/**
	 * Instantiates a new request template.
	 * 
	 * @param connection the connection
	 */
	public OnlineRequestTemplate(Connection connection)
	{
		super(connection);
	}
	
	/**
	 * Make request.
	 * 
	 * @param request the request
	 */
	// TODO: refine exceptions here...should be HVException
	public Object makeRequest(Object request) throws Exception {
		PersonInfo personInfo = RequestCtx.getPersonInfo();
		
		setUserAuthToken(personInfo.getUserAuthToken());
		setRecordId(personInfo.getRecordId());
		
		return super.makeRequest(request);
	}
}
